<template>
<div>
    <home-header ></home-header>
    <home-swiper :list='swiperList'></home-swiper>
    <home-icons :list ='iconList'></home-icons>
    <home-recommend :list ='recommendList'></home-recommend>
    <home-weekend :list ='weekendList'></home-weekend>
</div>
</template>
<script>
import HomeHeader from '@/pages/home/components/Header'
import HomeSwiper from '@/pages/home/components/Swiper'
import HomeIcons from '@/pages/home/components/Icons'
import HomeRecommend from '@/pages/home/components/Recommend'
import HomeWeekend from '@/pages/home/components/Weekend'
import axios from 'axios'
import {mapState} from 'vuex'
export default {
    name:'Home',
    components:{
      HomeHeader,
      HomeSwiper,
      HomeIcons,
      HomeRecommend,
      HomeWeekend
    },
    data () {
      return {
    
        swiperList:[],
        iconList:[],
        recommendList:[],
        weekendList:[],
        lastCity:''

      }
    },
    mounted(){
      this.lastCity = this.city
      this.getHomeInfo()
    },
    computed:{
      ...mapState(['city'])
    },
    methods:{
      getHomeInfo () {
        axios.get('/api/home.json?city='+this.city)
        .then(this.handler)
      },
      handler (res) {
          res=res.data
          if(res.ret &&res.data){
            const data= res.data
            this.swiperList=data.swiperList
            this.iconList=data.iconList
            this.recommendList = data.recommendList
            this.weekendList =data.weekendList
          }
      }
    },
    activated(){
      if(this.lastCity !== this.city ){
        this.lastCity = this.city
        this.getHomeInfo()
      } 
    }
    
}
</script>
<style lang="stylus" scoped>
   .home
     font-size:26px;
</style>
